from django import template
from django.conf import settings
import re

register = template.Library()

@register.inclusion_tag('gallery/templates/item.html', takes_context=True)
def render_item(context, item, *args, **kwargs):
    defaults = {
        'link': True,
        'caption': True,
        'gallery': False,
        'active': False,
        'category': False,
        'category_link': False,
        'width': 100,
    }
    args = get_args(defaults, kwargs)

    return {
        'item': item,
        'gallery': args['gallery'],
        'link': args['link'],
        'caption': args['caption'],
        'active': args['active'],
        'category_link': args['category'],
        'category': args['category'],
        'width': args['width'],
        'STATIC_URL': settings.STATIC_URL,
    }

def get_args(defaults, kwargs):
    parsed_args = {}

    for arg, default in defaults.iteritems():
        if arg in kwargs:
            parsed_args[arg] = kwargs[arg]
        else:
            parsed_args[arg] = default

    return parsed_args